package pers.lmd.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import pers.lmd.domain.R;
import pers.lmd.domain.dto.NoteDTO;
import pers.lmd.common.constant.ResultEnum;
import pers.lmd.domain.vo.NoteStudentVO;
import pers.lmd.domain.vo.NoteTeacherVO;
import pers.lmd.service.INoteService;
import pers.lmd.common.utils.ResultUtil;

/**
 * @Author lmd
 * @Date 2023/4/25 9:28
 */
@RequiredArgsConstructor
@RestController
@RequestMapping("/system")
@Tag(name = "假条控制器")
public class NoteController {
    private final INoteService INoteService;

    @Operation(summary = "分页查询假条,学生端")
    @GetMapping("/note/student")
    public R<Page<NoteStudentVO>> getNoteStudentByPage(@RequestParam(required = false,defaultValue = "1") int pageNo, @RequestParam(required = false,defaultValue = "5") int pageSize) {
        Page<NoteStudentVO> noteList = INoteService.getNoteStudentByPage(pageNo, pageSize);
        return ResultUtil.success(ResultEnum.SUCCESS,  noteList);
    }
    @Operation(summary = "分页查询假条，老师端")
    @GetMapping("/note/teacher")
    public R<Page<NoteTeacherVO>> getNoteTeacherByPage(@RequestParam(required = false,defaultValue = "1") int pageNo, @RequestParam(required = false,defaultValue = "5") int pageSize) {
        Page<NoteTeacherVO> noteList = INoteService.getNoteTeacherByPage(pageNo, pageSize);
        return ResultUtil.success(ResultEnum.SUCCESS, noteList);
    }
    @Operation(summary = "添加假条")
    @PostMapping("/note")
    public R<Void> addNote(@RequestBody NoteDTO noteDTO) {
        INoteService.addNote(noteDTO.getLeaveTime(), noteDTO.getBackTime(), noteDTO.getTravel(), noteDTO.getReason());
        return ResultUtil.success(ResultEnum.SUCCESS);
    }

    @Operation(summary = "更新假条状态")
    @PutMapping("/note/{id}/{applyStatus}")
    public R<Void> rejectNote(@PathVariable("id") Long id,@PathVariable("applyStatus") Integer applyStatus) {
        INoteService.updateNote(id,applyStatus);
        return ResultUtil.success(ResultEnum.SUCCESS);
    }
}
